/**
  ******************************************************************************
  * @file    timer1.h
  * @author  ashuai0110
  * @version V1.0
  * @date    2024-01-17
  * @brief   timer1驱动,适用于PIC16(L)F1788_9
  *
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

#ifndef __TIMER1_H
#define __TIMER1_H

#ifdef __cplusplus
extern "C" {
#endif

/* 包含头文件-----------------------------------------------------------------*/
#include "common.h"

/* 宏定义---------------------------------------------------------------------*/
#define TIMER1_GET_IT_FLAG()                (TMR1IF) /* 获取timer1溢出中断标志 */
#define TIMER1_CLR_IT_FLAG()                (TMR1IF = 0) /* 清除timer1溢出中断标志 */

#define TIMER1_GET_GIT_FLAG()               (TMR1GIF) /* 获取timer1门控中断标志 */
#define TIMER1_CLR_GIT_FLAG()               (TMR1GIF = 0) /* 清除timer1门控中断标志 */
    
#define TIMER1_SET_INITIAL_VAL(val)         (TMR1L = ((val) & 0xFF), TMR1H = ((val) >> 8)) /* 设置timer1计数初值 */
    
#define TIMER1_CMD(x)                       (TMR1ON = (x))
    
#define CCP1_GET_IT_FLAG()                  (CCP1IF)
#define CCP1_CLR_IT_FLAG()                  (CCP1IF = 0)
    
#define CCP2_GET_IT_FLAG()                  (CCP2IF)
#define CCP2_CLR_IT_FLAG()                  (CCP2IF = 0)

#define CCP3_GET_IT_FLAG()                  (CCP3IF)
#define CCP3_CLR_IT_FLAG()                  (CCP3IF = 0)
    
#define CCP1_SET_INITIAL_VAL(val)           (CCPR1L = ((val) & 0xFF), CCPR1H = ((val) >> 8))
    
#define CCP2_SET_INITIAL_VAL(val)           (CCPR2L = ((val) & 0xFF), CCPR2H = ((val) >> 8))
    
#define CCP3_SET_INITIAL_VAL(val)           (CCPR3L = ((val) & 0xFF), CCPR3H = ((val) >> 8))
    
/* 类型定义-------------------------------------------------------------------*/
    
/* 全局变量-------------------------------------------------------------------*/

/* 函数原型-------------------------------------------------------------------*/
void timer1_init(uint16_t value);
void timer1_de_init(void);
void timer1_update_it_cmd(uint8_t state);
void timer1_ccpx_init(uint8_t ccpx, uint16_t value);
void timer1_ccpx_it_cmd(uint8_t ccpx, uint8_t state);

#ifdef __cplusplus
}
#endif

#endif /* timer1.h */